package routes

import (
	v1 "easyVolunteer/api/v1"
	"easyVolunteer/middleware"
	"easyVolunteer/utils"
	"github.com/gin-gonic/gin"
)

func InitRouter() {
	gin.SetMode(utils.AppMode)
	r := gin.Default()
	r.NoRoute(v1.NotFound)

	unauth := r.Group("/api/v1")
	{
		unauth.POST("/ping", v1.PingPost) // 返回请求体
		unauth.POST("/login", v1.Login)
		unauth.GET("/test", v1.PING)                     //服务器基本联通测试
		unauth.GET("/activity/list", v1.GetActivityList) //获取活动列表
		unauth.GET("/activity/info", v1.GetActivityInfo) //获取活动的具体信息
	}

	auth := r.Group("api/v1/activity", middleware.JwtToken(), middleware.Admin())
	{
		auth.POST("/add", v1.CreateActivity)             //新建活动1
		auth.DELETE("/cancel", v1.CancelActivity)        //取消活动1
		auth.POST("/status", v1.ChangeActivityStatus)    //更改活动状态1
		auth.GET("/stopRecruit", v1.StopActivityRecruit) //停止招募1
		auth.GET("/finished", v1.ActivityFinished)       //活动完成1
		auth.GET("/admin", v1.GetAllOwnedActivity)       //管理员创建的所有的活动1
		auth.GET("/allVolunteer", v1.GetAllVolunteer)    //获得所有的志愿者1
		auth.GET("/count", v1.ActivityCount)             //获取活动数量
		auth.POST("/summary", v1.ActivitySummary)        //统计汇总数据并生成excel文件
	}

	user := r.Group("/api/v1/user", middleware.JwtToken())
	{
		user.GET("/Info", v1.GetUserInfo)                   //获取用户信息
		user.GET("/join", v1.JoinIn)                        //用户加入参加 活动
		user.GET("/quit", v1.QuitOut)                       //用户退出活动
		user.GET("/totalHours", v1.GetUserHour)             //获取用户总时长
		user.GET("/synTotalHours", v1.SyncAllActivityHours) //刷新所有的总时长到用户记录
		user.GET("/activities", v1.GetUserAllActivity)      //获取用户参加的所有活动
	}

	_ = r.Run(utils.HttpPort)
}
